/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package utils;

import java.io.IOException;
import java.io.OutputStream;
import java.security.InvalidAlgorithmParameterException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.UnrecoverableEntryException;
import java.security.cert.CertificateException;
import javax.xml.crypto.MarshalException;
import javax.xml.crypto.dsig.XMLSignatureException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import org.jdom.JDOMException;
import server.votesending.xmlsinger.XmlDSASigner;

/**
 *
 * @author Maciek
 */
public class SaveAndSign {
    public static void saveAndSign(OutputStream os,Object dpk, String keystore, String storepass, String keypass, String alias) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableEntryException, JDOMException, MarshalException, XMLSignatureException, TransformerConfigurationException, TransformerException, InvalidAlgorithmParameterException{
        
        XmlDSASigner xmlDsaSigner = new XmlDSASigner();
        xmlDsaSigner.initXml();
        xmlDsaSigner.initKeys(keystore , storepass, keypass, alias);
        
        org.w3c.dom.Document document = xmlDsaSigner.xmlSign(dpk);
        xmlDsaSigner.writeSigned(os, document);
        
    }
}
